home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Snippets / WatchCursor / WatchCursor.p next >
Encoding:
Text File  |  1994-05-03  |  2.2 KB  |  92 lines  |  [TEXT/R*ch]

  1. unit SpinningWatch;
  2.  
  3. interface
  4.  
  5. {Global variables}
  6.  var
  7.   gWatchHandle: CursHandle;
  8.   gSpinningWatchHandle: array[1..8] of CursHandle;
  9.   gSpinningWatchTimer: LongInt;
  10.   gSpinningWatchState: Integer;
  11.  
  12. {Call this at the beginning of your program.}
  13.  procedure InitWatch;
  14.  
  15. {Call ShowWatch as you would InitCursor.}
  16.  procedure ShowWatch;
  17.  
  18. {This routine is called when we want to first start displaying the moving
  19. watch cursor.}
  20.  procedure StartSpinningWatch;
  21.  
  22. {This routine is called when we want to rotate the watch to the next
  23. position.  We should}
  24. {just call this routine as often as possible; this routine worries about
  25. the timing itself.}
  26.  procedure SpinWatch;
  27.  
  28. {This routine deallocates the memory we used and inits the cursor.}
  29.  procedure StopSpinningWatch;
  30.  
  31. implementation
  32.  
  33.  procedure InitWatch;
  34.  begin
  35. {Get a handle to that standard watch cursor and hold on to it for the rest
  36. of the program.}
  37.   gWatchHandle := GetCursor(WatchCursor);
  38.  end;
  39.  
  40.  
  41.  procedure ShowWatch;
  42. {Set cursor to watch}
  43. {We have no routine ShowPointer, because we can simply say InitCursor.}
  44.  begin
  45.   SetCursor(gWatchHandle^^);
  46.  end;
  47.  
  48. {This routine is called when we first start want to display the moving
  49. watch cursor.}
  50.  procedure StartSpinningWatch;
  51.   var
  52.    counter: Integer;
  53.  begin
  54.   for counter := 1 to 7 do
  55.    gSpinningWatchHandle[counter] := GetCursor(Counter + 256);
  56.   gSpinningWatchState := 8;
  57.   gSpinningWatchTimer := TickCount;
  58.  end;
  59.  
  60. {This routine is called when we want to rotate the watch to the next
  61. position.  We should}
  62. {just call this routine as often as possible; this routine worries about
  63. the timing.}
  64.  procedure SpinWatch;
  65.   var
  66.    NewTime: LongInt;
  67.  begin
  68.   NewTime := TickCount;
  69.   if (NewTime - 30) > gSpinningWatchTimer then
  70.    begin
  71.     gSpinningWatchState := gSpinningWatchState + 1;
  72.     gSpinningWatchTimer := NewTime;
  73.     if gSpinningWatchState > 8 then
  74.      gSpinningWatchState := 1;
  75.     if gSpinningWatchState = 8 then
  76.      ShowWatch
  77.     else
  78.      SetCursor(gSpinningWatchHandle[gSpinningWatchState]^^);
  79.    end;
  80.  end;
  81.  
  82. {This routine deallocates the memory we used and inits the cursor.}
  83.  procedure StopSpinningWatch;
  84.   var
  85.    counter: Integer;
  86.  begin
  87.   for counter := 1 to 7 do
  88.    ReleaseResource(Handle(gSpinningWatchHandle[counter]));
  89.  end;
  90.  
  91. end.
  92.